import os
import xlrd


def get_all():
    """获取名单中的学生姓名和学号"""
    # 打开excel
    wb = xlrd.open_workbook('stu_name/names.xlsx')
    sh = wb.sheet_by_index(0)
    # 获取姓名列
    all_names = sh.col_values(2)[1:]
    print(all_names)
    # 获取学号列
    all_stu_no = sh.col_values(1)[1:]
    for index, stu_no in enumerate(all_stu_no):
        all_stu_no[index] = int(stu_no)
    print(all_stu_no)
    return all_stu_no, all_names

def get_file_names(path='works'):
    """获取路径下的文件名列表"""
    file_names = []
    for root, dirs, files in os.walk(path):
        file_names = files
        break

    sel_stuno = []
    sel_name = []
    for file_name in file_names:
        _1 = file_name.split('-')[0]
        _2 = file_name.split('-')[1]
        _3 = _2.split('.')
        sel_stuno.append(_1)
        sel_name.append(_3[0])
    return sel_stuno,sel_name

if __name__ == '__main__':
    all_stu_no, all_names = get_all()
    sel_stuno, sel_name = get_file_names()
    # 未交名单
    absent_name = []
    for name in all_names:
        if name not in sel_name:
            absent_name.append(name)

    print("共"+str(len(all_names))+"人")
    print("已交 ： " + str(len(sel_name)))
    print(sel_name)
    print("未交 ： " + str(len(absent_name)))
    print(absent_name)
